package com.kingdee.hackson.service.impl;

import com.kingdee.hackson.dao.IAuthDao;
import com.kingdee.hackson.entity.AuthEntity;
import com.kingdee.hackson.service.IAuthService;
import com.kingdee.hackson.utils.IDConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class AuthServiceImpl implements IAuthService {

    @Autowired
    private IAuthDao authDao;

    public List<Long> getIdListByParentOrgId(String prefixCode) {
        return authDao.getIdListByParentPrefixCode(prefixCode);
    }

    @Override
    public List<Long> getIdListByParentPrefixCode(String authCode) {
        return authDao.getIdListByParentPrefixCode(authCode);
    }

    @Override
    public void addRoot() {
        AuthEntity authEntity = new AuthEntity();
        String levelCode = "0a";
        String structNumer = "00";
        authEntity.setId(IDConvertUtils.encodeToLongId(0));
        authEntity.setAdminStruct(structNumer);
        authEntity.setLevelCode(levelCode);
        authEntity.setName("root");
        authEntity.setNumber("root");
        authEntity.setParentId(0L);
        authDao.batchInsert(Arrays.asList(authEntity));
    }

    @Override
    public void batchInsert(List<AuthEntity> datas) {
        authDao.batchInsert(datas);
    }

    @Override
    public void truncate() {
        authDao.truncate();
    }

    @Override
    public Long getIdListCountByParentPrefixCode(String prefix) {
        return authDao.getIdListCountByParentPrefixCode(prefix);
    }

    @Override
    public String queryAuthCodeByOrgId(Long orgId) {
        return authDao.queryAuthCodeByOrgId(orgId);
    }

    @Override
    public String queryStructNumberByOrgId(Long orgId) {
        return authDao.queryStructNumberByOrgId(orgId);
    }

}
